import os
from PIL import Image
import math
import operator
from functools import reduce


def fileSizeCompared():
    fileMap = []
    filePath = "/Users/xuyihang/Downloads/新建文件夹/";

    _listdir = os.listdir( filePath )
    for fileName in _listdir:
        fileMap.append( fileName )

    numberMap = {}
    for path_one in fileMap:
        fileNumberList = []
        for path_two in fileMap:
            _path_one = filePath + path_one
            _path_two = filePath + path_two
            image1 = Image.open( _path_one )
            image2 = Image.open( _path_two )
            h1 = image1.histogram()
            h2 = image2.histogram()
            if path_two != path_one:
                result = math.sqrt(
                    reduce( operator.add, list( map( lambda a, b: (a - b) ** 2, h1, h2 ) ) ) / len( h1 ) )
                if result == 0:
                    print( path_one + " —————————— " + path_two )
                    fileNumberList.append( path_two )

        numberMap[path_one] = fileNumberList
    print(numberMap)

if __name__ == '__main__':
    fileSizeCompared()




